<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('应收合同详情')" />
</head>
<style>
	body{height:auto;font-family: "Microsoft YaHei";}
	button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
</style>
<body class="hold-transition box box-main">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 select-table table-striped">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								<p>合同编号：</p>
								<input type="text" name="contractNo"/>
							</li>
							<li>
								<p>合同名称：</p>
								<input type="text" name="contractName"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
				<input id="contractNo" type="hidden"/>
				<input id="contractName" type="hidden"/>
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
        var prefix = ctx + "system/yingshou";
        $(function() {
            var options = {
                url: prefix + "/receivablesContractDetail",
                sortName: "contractSignTime",
                sortOrder: "desc",
                modalName: "应收合同详情",
                escape: false,
                showPageGo: true,
                rememberSelected: true,
                mobileResponsive: false, //本弹窗宽度太小，系统默认显示cardview，所以要加上此属性，强制让他显示列表
                showRefresh: false,
				showSearch:false,
                showFooter: true,
                showToggle: false,
                showColumns: false,
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
					field : 'contractNo',
					title : '合同编号',
                    sortable: true,
                },
				{
                    field : 'contractName',
                    title : '合同名称'
				},
				{
					field : 'custom',
					title : '客户'
				},
				{
					field : 'contractSignTime',
					title : '合同签订日期',
                    sortable: true
				},
				{
					field : 'booking',
					title : '合同金额',
                    sortable: true
				},
				{
					field : 'number',
					title : '应收金额',
                    sortable: true,
                    footerFormatter: function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].number);
                        }
                        return "应收总金额：" + sumBalance;
                    }
				},
				{
					field : 'xsPrincipalName',
					title : '销售负责人',
					sortable: true
				},
				{
					field : 'jfPrincipalName',
					title : '交付负责人',
					sortable: true
				}],
                onClickRow: function(row, $element){
					$('#contractNo').val(row.contractNo);
					$('#contractName').val(row.contractName);
                    $('.info').removeClass('info');//移除class
                    $($element).addClass('info');//添加class
				}
            };
            $.table.init(options);

            initChildTable = function(index, row, $detail) {
                var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
                $(childTable).bootstrapTable({
                    url: ctx + "system/yingshou/receivablesContractDetail/stageList",
                    method: 'post',
                    sidePagination: "server",
                    contentType: "application/x-www-form-urlencoded",
                    rowStyle: rowStyle,
                    queryParams : {
                        contractId: row.contractId
                    },
                    columns: [{
						field : 'stageNo',
						title : '阶段序号'
					},
					{
						field : 'stageName',
						title : '名称'
					},
					{
						field : 'stagePrincipal1',
						title : '负责人一'
					},
					{
						field : 'stageMoney',
						title : '合同金额'
					},
					{
						field : 'actualMoney',
						title : '收款金额'
					},
					{
						field : 'contractEndTime',
						title : '合同工期结束时间',
                        formatter: function(value, row, index){
                            return changeDateFormat(value);
                        }
					},
					{
						field : 'predictEndTime',
						title : '实施预测结束时间',
                        formatter: function(value, row, index){
                            return changeDateFormat(value);
                        }
					},
					{
						field : 'actualEndTime',
						title : '交付实际结束时间',
                        formatter: function(value, row, index){
                            return changeDateFormat(value);
                        }
					}]
                });
            };

            function changeDateFormat(cellval){
                var dateVal = cellval + "";
                if (cellval != null) {
                    dateVal = dateVal.split(' ');
                    return dateVal[0];
                } else {
                    return '-';
				}
			}
            function rowStyle(row, index) {
                console.log(row);
                console.log(index);
                var classes = ['active', 'success', 'info', 'warning', 'danger'];
                if(row.actualEndTime == null || row.actualEndTime == ''){
                    return {};
				} else {
                    if (row.stageMoney > row.actualMoney) {
                        return {
                            classes: classes[4]
                        };
                    } else {
                        return {
                            classes: classes[1]
                        };
					}
				}
            }
        });
	</script>
</body>
</html>
